package at.fhj.itm11.fotorater.rest;

import java.util.logging.Logger;

import javax.faces.bean.RequestScoped;
import javax.inject.Inject;
import javax.validation.Validator;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

import at.fhj.itm11.fotorater.service.PhotoRatingService;

@Path("/rate")
@RequestScoped
public class PhotoRatingRESTService {

	@Inject
	private Logger log;

	@Inject
	private Validator validator;
	
	@Inject
	PhotoRatingService photoService;
	
	@GET
	@Path("/like/{id:[0-9][0-9]*}")
	public Response likePhoto(@PathParam("id") long id) {
		try {
			photoService.likePhoto(id);	
			return Response.status(200).entity("Rating done.").build();
		} catch(Exception e) {
			e.printStackTrace();
			return Response.status(500).entity("Rating failed.").build();
		}
	}
	
	@GET
	@Path("/dislike/{id:[0-9][0-9]*}")
	public Response dislikePhoto(@PathParam("id") long id) {
		try {
			photoService.dislikePhoto(id);	
			return Response.status(200).entity("Rating done.").build();
		} catch(Exception e) {
			e.printStackTrace();
			return Response.status(500).entity("Rating failed.").build();
		}
	}
}
